package com.yangrd.airship.generator.page;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yangrd.airship.generator.page.base.AbstractMetaInfo;
import com.yangrd.airship.generator.support.utils.HumpUtils;
import com.yangrd.airship.generator.support.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Optional;

/**
 * @author yangrd
 * @date 2021/11/8
 */
@EqualsAndHashCode(callSuper = false)
@Data
@AllArgsConstructor(staticName = "of")
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PageGeneratorDefine extends AbstractMetaInfo<PageGeneratorDefine> {

    private String name;

    private List<PageQueryCriteria> queryCriteriaList;

    private List<PageColumn> columns;

    private List<PageAction> actions;

    public Class<?> getType(String name) {
        Optional<Class<?>> classOptional = columns.stream().filter(tableColumn -> tableColumn.getName().equals(name)).findFirst().map(PageColumn::getType);
        return classOptional.orElse(String.class);
    }

    public String getName() {
        return StringUtils.capFirst(name);
    }

    public String lineToHump(String str){
        return HumpUtils.lineToHump(str.toLowerCase());
    }
}
